export const isExternal = (path) => {
  const reg = /^(https?:|mailto:|tel:)/
  return reg.test(path)
}

export const isArray = (arg) => {
  if (typeof Array.isArray === "undefined") {
    return Object.prototype.toString.call(arg) === "[object Array]"
  }
  return Array.isArray(arg)
}

export function isString(str) {
  if (typeof str === "string" || str instanceof String) {
    return true
  }
  return false
}

export const isValidURL = (url) => {
  const reg =
    // /^(https?|ftp):\/\/([a-zA-Z0-9.-]+(:[a-zA-Z0-9.&%$-]+)*@)*((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9][0-9]?)(\.(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])){3}|([a-zA-Z0-9-]+\.)*[a-zA-Z0-9-]+\.(com|edu|gov|int|mil|net|org|biz|arpa|info|name|pro|aero|coop|museum|[a-zA-Z]{2}))(:[0-9]+)*(\/($|[a-zA-Z0-9.,?'\\+&%$#=~_-]+))*$/
    /^(((ht|f)tps?):\/\/)?([^!@#$%^&*?.\s-]([^!@#$%^&*?.\s]{0,63}[^!@#$%^&*?.\s])?\.)+[a-z]{2,6}\/?/
  return reg.test(url)
}

// 验证手机号 
export const isValidPhone = (url) => {
  const reg = /^(0|86|17951)?(13[0-9]|14[57]|15[012356789]|17[678]|18[0-9]|19[012356789])[0-9]{8}$/;
  return reg.test(url);
}
// 验证邮箱 
export const isValidEmail = (url) => {
  const reg = /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
  return reg.test(url);
}

// 密码：数字、字母 8-64位
export const isValidPwd = (url) => {
  // const reg = /^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{8,20}$/;
  // const reg = /((^(?=.*[a-z])(?=.*[A-Z])(?=.*\W)[\da-zA-Z\W]{8,16}$)|(^(?=.*\d)(?=.*[A-Z])(?=.*\W)[\da-zA-Z\W]{8,16}$)|(^(?=.*\d)(?=.*[a-z])(?=.*\W)[\da-zA-Z\W]{8,16}$)|(^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])[\da-zA-Z\W]{8,}$))/;
  const reg = /^(?![a-zA-Z]+$)(?![A-Z0-9]+$)(?![A-Z\W_]+$)(?![a-z0-9]+$)(?![a-z\W_]+$)(?![0-9\W_]+$)[a-zA-Z0-9\W_]{8,}$/
  return reg.test(url);
}
// 数字、字母 18位 社会统一信用代码
export const isValidHosID = (url) => {
  const reg = /^[0-9A-Za-z]{18}$/;
  return reg.test(url);
}
// 数字 12位
export const isValidPharmacyID = (url) => {
  const reg = /^[0-9]{12}$/;
  return reg.test(url);
}

// 数字、字母 12位
export const isValidYPID = (url) => {
  const reg = /^[0-9A-Za-z]{12}$/;
  return reg.test(url);
}
// 数字、字母 8位
export const isValidOtherID = (url) => {
  const reg = /^[0-9A-Za-z]{8}$/;
  return reg.test(url);
}

// 私钥：数字、字母 64位
export const isValidSKP = (url) => {
  const reg = /^[0-9A-Za-z]{64}$/;
  return reg.test(url);
}
// 身份证验证
export const isValidID = (url) => {
  const reg = /^[1-9]\d{5}(?:18|19|20)\d{2}(?:0[1-9]|10|11|12)(?:0[1-9]|[1-2]\d|30|31)\d{3}[\dXx]$/;
  return reg.test(url);
}
//2-36个字符，不能以特殊字符及数字开头，只可包含特殊字符中的"."、"_"或"-"
export const nameValidator = (url) => {
  const reg = /^[A-Za-z\u4e00-\u9fa5]+[\u4e00-\u9fa5_0-9A-Za-z._-]*$/;
  return reg.test(url);
}
